package com.example.a313ldy.yuejian_17.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a313ldy.yuejian_17.Activity.Master_detail;
import com.example.a313ldy.yuejian_17.Bean.Master;
import com.example.a313ldy.yuejian_17.Gloablecalss.Yuejian;
import com.example.a313ldy.yuejian_17.R;
import com.squareup.picasso.Picasso;

import java.util.List;



public class MasterAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Master.ClubcoachlistEntity> mList;
    public LayoutInflater mLayoutInflater;

    public MasterAdapter(Context mContext, List<Master.ClubcoachlistEntity> List) {
        this.mContext = mContext;
        this.mList = List;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_masterlist, parent, false);
        ViewHolder v = new ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Master.ClubcoachlistEntity master = (Master.ClubcoachlistEntity) mList.get(position);
        if (null == master)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.likes_num.setText(master.getMaster_like()+"");
        viewHolder.master_name.setText(master.getMaster_name());
        if(!master.getMaster_picture().isEmpty()) {
            Picasso.with(mContext).load(Yuejian.IMG_URL+master.getMaster_picture()).into(viewHolder.img_club);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(mContext, Master_detail.class);
                String img = Yuejian.IMG_URL+master.getMaster_picture();
                String master_name = master.getMaster_name();

                intent.putExtra("img",img);
                intent.putExtra("master_name",master_name);
                intent.putExtra("intro",master.getMaster_intro());
                //intent.putExtra("address",master.getMaster_address());

                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView master_name,likes_num;
        ImageView img_club,img_like;

        public ViewHolder(View itemView) {
            super(itemView);
            img_like = (ImageView) itemView.findViewById(R.id.like);
            likes_num = (TextView) itemView.findViewById(R.id.likes_num);
            master_name = (TextView) itemView.findViewById(R.id.master_name);
            img_club = (ImageView) itemView.findViewById(R.id.img_club);

        }
    }
}
